﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Acoris.Animation
{
    /// <summary>
    /// 表示时间轴
    /// </summary>
    public sealed class Timeline
    {
        private TimeSpan m_elapsedTime;
        private TimeSpan m_totalTime;
        private DateTime m_now;
        private SynchronizationContext m_threadContext;

        public Timeline()
        {
            m_now = DateTime.Now;
            m_elapsedTime = DateTime.Now - m_now;
            m_threadContext = SynchronizationContext.Current;
        }

        public void VerifyAccess()
        {
            if(m_threadContext != SynchronizationContext.Current)
            {
                throw new InvalidOperationException("");
            }
        }

        public AnimationTimeSnapshot MakeSnapshot()
        {
            // verify thread access
            VerifyAccess();
            var snapshot = new AnimationTimeSnapshot(m_elapsedTime,m_totalTime);
            m_elapsedTime = DateTime.Now - m_now;
            m_totalTime.Add(m_elapsedTime);
            m_now = DateTime.Now;
            return snapshot;
        }
    }
}
